
import {message} from 'antd';


export default class {
    message = message

    makeAreasList = ({rowNum = 0, colNum = 0}) => {
        let list = [];
    
        for (let i=0;i<rowNum;i++) {
            for(let j=0;j<colNum;j++) {
                list.push({
                    label: `${i+1}行${j+1}列`,
                    value: `${i}-${j}`
                });
            }
        }
    
        return list;
    }

    // 获取一个元素相对于targetEl的位置 如果不设置targetEl则取到ducument 
    getElPos = (el, targetEl) => {
        let pos = {
            top: el.offsetTop,
            left: el.offsetLeft
        };

        if (targetEl && el === targetEl) {
            return pos;
        }

        if (el.offsetParent  && el.offsetParent  !== document) {
            let parentPos = this.getElPos(el.offsetParent , targetEl);

            pos.top = pos.top + parentPos.top;
            pos.left = pos.left + parentPos.left;
        }

        return pos;
    }

    // 设置config里的元素属性
    setConfigItem = (config, id, key, value) => {

        config.forEach((item, index) => {
            if (Array.isArray(item)) {
                config[index] = this.setConfigItem(item, id, key, value);
            }
            else if (item && item.id === id) {
                item[key] = value;
            } else if (item && Array.isArray(item.children)) {
                item.children = this.setConfigItem(item.children, id, key, value);
            }
        });

        return [...config];
    }
}